package tw.com.hitevision.whiteboard.android.stateFile;

import android.graphics.PointF;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.ColorInt;

import tw.com.hitevision.whiteboard.android.render.ProtractorItem;
import tw.com.hitevision.whiteboard.android.widgets.MeasurementTools.ProtractorPaintMode;

public class ProtractorItemStateFile extends BaseStateFile {
    private PointF centerP;
    private PointF startP;
    private float protractorDegree;
    private int modeOrdinal;
    private @ColorInt
    int strokeColor;
    private float strokeWidth;
    private boolean showDegree;

    public ProtractorItemStateFile(ProtractorItem item, @ColorInt int strokeColor, float strokeWidth,
                                   PointF centerP, PointF startP, float protractorDegree, ProtractorPaintMode mode, boolean showDegree) {
        super(item);
        this.setClassName(ProtractorItem.class.getSimpleName());

        this.strokeColor = strokeColor;
        this.strokeWidth = strokeWidth;
        this.centerP = new PointF(centerP.x, centerP.y);
        this.startP = new PointF(startP.x, startP.y);
        this.protractorDegree = protractorDegree;
        this.modeOrdinal = mode.ordinal();
        this.showDegree = showDegree;
    }

    public static final Parcelable.Creator<ProtractorItemStateFile> CREATOR = new Parcelable.Creator<ProtractorItemStateFile>() {
        @Override
        public ProtractorItemStateFile createFromParcel(Parcel source) {
            return new ProtractorItemStateFile(source);
        }

        @Override
        public ProtractorItemStateFile[] newArray(int size) {
            return new ProtractorItemStateFile[0];
        }
    };

    protected ProtractorItemStateFile(Parcel in) {
        super(in);
        float[] array = in.createFloatArray();
        centerP = new PointF(array[0], array[1]);
        array = in.createFloatArray();
        startP = new PointF(array[0], array[1]);
        protractorDegree = in.readFloat();
        modeOrdinal = in.readInt();
        strokeColor = in.readInt();
        strokeWidth = in.readFloat();
        showDegree = in.readByte() != 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeFloatArray(new float[]{centerP.x, centerP.y});
        dest.writeFloatArray(new float[]{startP.x, startP.y});
        dest.writeFloat(protractorDegree);
        dest.writeInt(modeOrdinal);
        dest.writeInt(strokeColor);
        dest.writeFloat(strokeWidth);
        dest.writeByte((byte) (showDegree ? 1 : 0));
    }

    public void setCenterP(PointF centerP) {
        this.centerP = centerP;
    }

    public PointF getCenterP() {
        return centerP;
    }

    public void setStartP(PointF startP) {
        this.startP = startP;
    }

    public PointF getStartP() {
        return startP;
    }

    public void setProtractorDegree(float protractorDegree) {
        this.protractorDegree = protractorDegree;
    }

    public float getProtractorDegree() {
        return protractorDegree;
    }

    public void setStrokeColor(int strokeColor) {
        this.strokeColor = strokeColor;
    }

    public int getStrokeColor() {
        return strokeColor;
    }

    public void setStrokeWidth(float strokeWidth) {
        this.strokeWidth = strokeWidth;
    }

    public float getStrokeWidth() {
        return strokeWidth;
    }

    public void setModeOrdinal(int modeOrdinal) {
        this.modeOrdinal = modeOrdinal;
    }

    public int getModeOrdinal() {
        return modeOrdinal;
    }

    public void setShowDegree(boolean showDegree) {
        this.showDegree = showDegree;
    }

    public boolean isShowDegree() {
        return showDegree;
    }
}
